# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-qed
pkgver=2.9.1
pkgrel=1
pkgdesc='Quality Ensured Documentation'
arch=(any)
url='https://github.com/rubyworks/qed'
license=(BSD)
depends=(ruby-ansi ruby-brass ruby-facets)
checkdepends=(ruby-ae)
options=(!emptydirs)
source=(https://github.com/rubyworks/qed/archive/$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('2eab436b4b419b36aa67fa007eb59c2cb81ab7f2376c8124a18cace77b3811a8')

prepare() {
  cd qed-$pkgver
  # https://github.com/rubyworks/facets/issues/179
  sed -i "s/tabto/margin/" lib/qed/reporter/verbatim.rb lib/qed/reporter/linear.rb lib/qed/step.rb
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd qed-$pkgver
  gem build .gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    qed-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd qed-$pkgver
  PATH="$PWD/tmp_install/usr/bin:$PATH" GEM_HOME="tmp_install/$_gemdir" qed
}

package() {
  cd qed-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
